package com.henu.acmrating.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.henu.acmrating.dao.ProblemMapper;
import com.henu.acmrating.pojo.Problem;
import com.henu.acmrating.pojo.ProblemWithUser;
import com.henu.acmrating.pojo.RankItem;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

@Service
public class ProblemService {

    @Resource
    private ProblemMapper problemMapper;


    public int deleteByPrimaryKey(Integer id) {
        return problemMapper.deleteByPrimaryKey(id);
    }


    public int insert(Problem record) {
        return problemMapper.insert(record);
    }


    public int insertOrUpdate(Problem record) {
        return problemMapper.insertOrUpdate(record);
    }


    public int insertOrUpdateSelective(Problem record) {
        return problemMapper.insertOrUpdateSelective(record);
    }


    public int insertSelective(Problem record) {
        return problemMapper.insertSelective(record);
    }


    public Problem selectByPrimaryKey(Integer id) {
        return problemMapper.selectByPrimaryKey(id);
    }


    public int updateByPrimaryKeySelective(Problem record) {
        return problemMapper.updateByPrimaryKeySelective(record);
    }


    public int updateByPrimaryKey(Problem record) {
        return problemMapper.updateByPrimaryKey(record);
    }


    public int updateBatch(List<Problem> list) {
        return problemMapper.updateBatch(list);
    }


    public int batchInsert(List<Problem> list) {
        return problemMapper.batchInsert(list);
    }

    public int deleteByUserIdAndOjName(Integer userId, String ojName) {
        return problemMapper.deleteByUserIdAndOjName(userId, ojName);
    }


    public PageInfo<Problem> selectAllwithPage(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        return new PageInfo<>(problemMapper.selectAll());
    }

    public PageInfo<ProblemWithUser> problemWithUserwithPage(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        return new PageInfo<>(problemMapper.problemWithUser());
    }

    public List<Problem> selectByUserIdAndProblemUrl(Integer userId, String problemUrl) {
        return problemMapper.selectByUserIdAndProblemUrl(userId, problemUrl);
    }

    public List<Problem> selectByOjName(String ojName) {
        return problemMapper.selectByOjName(ojName);
    }

    public PageInfo<RankItem> showRankwithPage(int page, int pageSize, Integer days, Integer role) {
        PageHelper.startPage(page, pageSize);
        return new PageInfo<>(problemMapper.showRank(days, role));
    }


    public PageInfo<RankItem> showRankByUserwithPage(int page, int pageSize, Integer days, String userName) {
        PageHelper.startPage(page, pageSize);
        return new PageInfo<>(problemMapper.showRankByUser(days, userName));
    }

    public PageInfo<ProblemWithUser> problemByUserNamewithPage(int page, int pageSize, String userName) {
        PageHelper.startPage(page, pageSize);
        return new PageInfo<>(problemMapper.problemByUserName(userName));
    }



    public RankItem showRankByUserId(Integer days, Integer userId) {
        return problemMapper.showRankByUserId(days, userId);
    }

    public List<RankItem> showRank(Integer days, Integer role) {
        return problemMapper.showRank(days, role);
    }

    public List<Problem> selectByRunIdAndOjName(String runId, String ojName) {
        return problemMapper.selectByRunIdAndOjName(runId, ojName);
    }


    public List<Problem> selectByUserIdAndProblemUrls(Integer userId, Set<String> problemUrls) {
        return problemMapper.selectByUserIdAndProblemUrls(userId, problemUrls);
    }
}

